package com.cloud.cloudshop.shop.redisdao;

import com.cloud.common.entity.GoodsEntity;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 54485
 */
@Repository
public class RedisUserGoodsRepository {

    private final HashOperations hashOperations;

    private final RedisTemplate redisTemplate;

    public RedisUserGoodsRepository(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
        this.hashOperations = redisTemplate.opsForHash();
    }


    public void save(GoodsEntity goodsEntity) {
        hashOperations.put("goodsEntity", goodsEntity.getId(), goodsEntity);
    }

    public List<GoodsEntity> findAll() {
        return hashOperations.values("goodsEntity");
    }

    public GoodsEntity findById(String id) {
        return (GoodsEntity) hashOperations.get("goodsEntity", id);
    }

    public void update(GoodsEntity goodsEntity) {
        save(goodsEntity);
    }

    public void delete(String id) {
        hashOperations.delete("goodsEntity", id);
    }

    public void multiGetUsers(List<String> goodsEntityIds) {
        hashOperations.multiGet("goodsEntity", goodsEntityIds);
    }

}
